package com.paradogs.demo.logic.manager;

import com.paradogs.demo.logic.manager.base.BaseManager;
import com.paradogs.framework.common.dao.RoleDao;
import com.paradogs.framework.common.data.RoleLevel;
import com.paradogs.framework.common.entity.Role;
import com.paradogs.framework.core.annoations.tick.PRTick;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: yumi
 * @date: 2023/11/30  15:22
 * @Description: TODO
 */
@Slf4j
@Component
@Scope("prototype")
public class RoleManager extends BaseManager<Role, RoleDao> {

    public void addExp() {
        RoleLevel.Config roleLevelConfig = RoleLevel.getConfig(); // 玩家经验配置表
        Role role = getData();
        RoleLevel.Data cfg = RoleLevel.getData(role.getLevel() + 1); // 下一级升级信息
        if (cfg == null || role.getLevel() >= roleLevelConfig.getMaxLevel()) {
            log.debug("已经达到最高级");
            return;
        }
        role.setExp(role.getExp() + 100);
        if (role.getExp() > cfg.getExp()) {
            role.setExp(role.getExp() - cfg.getExp());
            role.setLevel(role.getLevel() + 1);
        }
        updateData(role);
    }

}
